const {get_class_info} = require('../../Class/get_class_video.js');
const classInfo = new get_class_info();

Page({
  data:{
    option1:[],
    option2:[],
    option3:[],
    value1:1
  },

  BindChange(e){
    if(e === null){
      var tab_id = 0
      var menu_id = 0
    }else{
      var tab_id = parseInt(e.currentTarget.dataset.id)
      var menu_id = e.detail
    }
    wx.showLoading({title: '数据通信中',})
    const result = classInfo.Basetext_Getclass(tab_id,menu_id,this.data.class_result)
    this.setData({
      class_text : result.class_text,
      class : result.total_class,
      tab_id,
      menu_id,
      value1:null,
      value2:null
    })
    wx.hideLoading()
  },

  // 需要重新將this.data.class給進行賦值
  GetZhangjie(e){
    wx.showLoading({title: '数据通信中',})
    const result = classInfo.Basetext_Getclass(this.data.tab_id,this.data.menu_id,this.data.class_result)

    var id = e.currentTarget.dataset.id 
    var class_selected = []
    var class_text = result.class_text
    for (let index = 0; index < result.total_class.length; index++) {
      if(class_text[id].text === result.total_class[index].title){
        class_selected.push(result.total_class[index])
        class_text[id].flag = true
      }
    }
    this.setData({
      class : class_selected,
      class_text
    })
    wx.hideLoading()
  },

  GoVideo(e){
    var id = e.currentTarget.dataset.id
    const video_info = JSON.stringify(this.data.class[id])
    wx.navigateTo({
      url: '/pages/OnlineClass/classvideo/classvideo?video_info='+ video_info,
    })
  },

  async onLoad(options){
    wx.showLoading({title: '数据通信中'})
    const class_result = await classInfo.GetOnlineClass();
    this.setData({
      option1:class_result.hyy_options,
      option2:class_result.xinwen_options,
      class_result
    })
    this.BindChange(null)
    wx.hideLoading()
  }
})